<?php

namespace app\common\validate;

use think\Validate;

class Member extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...]
     *
     * @var array
     */	
	protected $rule = [
	    'username|会员账号' => 'require|unique:member',
        'password|会员密码' => 'require',
        'conpass|确认密码' => 'require|confirm:password',
        'oldpass|原密码' => 'require',
        'newpass|新密码' => 'require',
        'newconpass|确定密码' => 'require|confirm:newpass',
        'nickname|会员昵称' => 'require',
        'email|邮箱' => 'require|email|unique:member'
    ];
    
    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'
     *
     * @var array
     */	
    protected $message = [
        'conpass.confirm' => '两次密码不一致',
        'newconpass.confirm' => '两次密码不一致'
    ];

    //添加场景
    public function sceneAdd(){
        $this->only(['username', 'password', 'conpass', 'nickname', 'email']);
    }

    //编辑场景
    public function sceneEdit(){
        $this->only(['oldpass', 'newpass', 'newconpass', 'nickname'])->remove('conpass','confirm')->append('conpass', 'confirm:newpass');
    }

    //会员登陆
    public function sceneLogin()
    {
        $this->only(['username', 'password'])->remove('username', 'unique');
    }
}
